mathematical manipulation in R using dplyr